<template>
  <div class="execution">
    <basic-container>
      <el-card class="filter-container" shadow="never">
        <div style="margin-top: 10px">
          <el-form :inline="true" size="small" label-width="140px">
            <el-form-item label="订单编号：">
              <el-input v-model="listQuery.orderSn"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button @click="getList" type="primary" size="small"
                >查询结果</el-button
              >
              <el-button @click="handleResetSearch" size="small">
                重置
              </el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
      <div style="margin-top: 10px">
        <el-table
          :data="list"
          border
          :header-cell-style="{ color: '#4D4D4D', background: '#fafafa' }"
        >
          <el-table-column
            label="订单编号"
            align="center"
            show-overflow-tooltip
            prop="orderSn"
          ></el-table-column>
          <el-table-column
            label="支付金额"
            align="center"
            prop="totalAmount"
          ></el-table-column>
          <el-table-column label="支付类型" align="center" prop="payType">
            <template slot-scope="scope">
              <p>{{ scope.row.payType | payTypeFilters }}</p>
            </template>
          </el-table-column>
          <el-table-column label="来源" align="center" prop="sourceType">
            <template slot-scope="scope">
              <p>{{ scope.row.sourceType | formatSourceType }}</p>
            </template>
          </el-table-column>
          <el-table-column
            label="技术收益金额"
            align="center"
            prop="technologyIncomeAmount"
          ></el-table-column>
          <el-table-column label="状态" align="center" prop="sourceType">
            <template slot-scope="scope">
              <p>{{ scope.row.technologySettlement | technologySettlementType }}</p>
            </template>
          </el-table-column>
          <el-table-column
            label="支付时间"
            align="center"
            prop="paymentTime"
          ></el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="{ row }" v-if="row.storeSettlement == 2">
              <el-button size="mini" @click="handleSettlement(row)" type="text" plain
                >结算</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-container">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          layout="total, sizes,prev, pager, next,jumper"
          :page-size="listQuery.size"
          :page-sizes="[5, 10, 15]"
          :current-page.sync="listQuery.current"
          :total="total"
        >
        </el-pagination>
      </div>
    </basic-container>
  </div>
</template>
<script>
import "@/styles/index.scss";
import { technologyOrder, getTechnologyStatus } from "@/api/profit/technology/index";

const defaultListQuery = {
  current: 1,
  size: 10,
  orderSn: null,
};

export default {
  data() {
    return {
      options: [],
      listQuery: Object.assign({}, defaultListQuery),
      list: [],
      total: 0,
    };
  },
  created() {
    this.getList();
  },
  filters: {
    payTypeFilters(value) {
      if (value === 1) {
        return "支付宝";
      } else if (value === 2) {
        return "微信";
      }
    },
    formatSourceType(value) {
      if (value === 1) {
        return "app";
      } else if (value === 2) {
        return "小程序";
      } else if (value === 3) {
        return "h5";
      }
    },
    technologySettlementType(value) {
      if (value === 1) {
        return "结算";
      } else if (value === 2) {
        return "未结算";
      }
    },
  },
  methods: {
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.current = val;
      this.getList();
    },
    getList() {
      technologyOrder(this.listQuery).then((res) => {
        this.list = res.data.data.records;
        this.total = res.data.data.total;
      });
    },
    handleResetSearch() {
      this.listQuery = Object.assign({}, this.defaultListQuery);
    },
    handleSettlement(row) {
      let that = this;
      that
        .$confirm("是否确认结算", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
        .then(function () {
          getTechnologyStatus({ id : row.id }).then(res => {
            if (res.data.code === 200) {
              that.$message({
                message: res.data.msg,
                type: "success",
                duration: 1000,
              });
              that.getList();
            } else {
              that.$message({
                message: res.data.msg,
                type: "warning",
                duration: 1000,
              });
            }
          })
        })
    }
  },
};
</script>
